package com.xcc.wavzmp3;

import android.text.TextUtils;

import org.json.JSONException;
import org.json.JSONObject;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;


/****
 * 通用的模型类
 *
 * @author 卡伦人
 * @email ka-lun-ren@foxmail.com 2015年3月30日 下午1:37:53
 ****/
public class MSCMode implements Serializable {

    private static final long serialVersionUID = -6881808049981560055L;

    public MSCMode() {
        init();
    }

    public MSCMode(String title) {
        init();
        this.title = title;
    }

    /**
     * 通用build
     **/
    public MSCMode(JSONObject mscjsonObject) {
        init();
        setJson(mscjsonObject);
    }

    public MSCMode(String title, String id) {
        init();
        this.title = title;
        this.id = id;
    }

    private void init() {


        this.id = "";
        this.title = "";
        this.info = "";
    }

    /**
     * 类型
     **/
    public int type;

    /**
     * 类型
     **/
    public float typef;

    /**
     * 标题
     **/
    public String title;


    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    /**
     * 内容
     **/
    public String info;

    /**
     * json
     **/
    public String json;

    /**
     * MSCJSONArray
     **/
    public String jsonarray;


    public int optInt(String key) {
        return getJson().optInt(key);
    }

    public String optString(String key) {
        return getJson().optString(key);
    }



    public JSONObject getJson() {

        if (TextUtils.isEmpty(json)) {
            json = "{}";
        }

        JSONObject mscjsonObject;

        try {
            mscjsonObject = new JSONObject(json);
            return mscjsonObject;
        } catch (JSONException e) {
            e.printStackTrace();
        }
        return new JSONObject();

    }

    /**
     * 重新通过json赋值
     **/
    public void setJson(JSONObject mscjsonObject) {

        json = mscjsonObject.toString();
    }

    @Override
    public boolean equals(Object obj) {

        if (this == obj)
            return true;

        if (obj == null)
            return false;

        if (getClass() != obj.getClass())
            return false;

        MSCMode m = (MSCMode) obj;

        if (id.equals(m.id)) {
            return true;
        }

        return super.equals(obj);
    }

    public boolean ba;

    public boolean isBa() {
        return ba;
    }

    public void setBa(boolean ba) {
        this.ba = ba;
    }

    public String id;

    public List<MSCMode> alldata;

    public int getType() {
        return type;
    }

    public void setType(int type) {
        this.type = type;
    }

    public String getInfo() {
        return info;
    }

    public void setInfo(String info) {
        this.info = info;
    }


    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    @Override
    public String toString() {
        return "MSCMode{" +
                "type=" + type +
                ", typef=" + typef +
                ", title='" + title + '\'' +
                ", info='" + info + '\'' +
                ", ba=" + ba +
                ", id='" + id + '\'' +
                '}';
    }


}
